package com.yuexun.dhdoctor.module.contractmanage.ui;

import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.contractmanage.adapter.ContractManageTestDetailAdapter;
import com.yuexun.dhdoctor.module.contractmanage.bean.ContractManageTestDetailBean;
import com.yuexun.dhdoctor.module.contractmanage.model.impl.ContractManageModel;
import com.yuexun.dhdoctor.module.contractmanage.presenter.IContractManageTestDetailPresenter;
import com.yuexun.dhdoctor.module.contractmanage.presenter.impl.ContractManageTestDetailPresenter;
import com.yuexun.dhdoctor.module.contractmanage.ui.view.IContractManageTestDetailView;
import com.yuexun.dhdoctor.widget.EmptyLayout;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2016/10/27.
 */
public class Act_ContractManageTestDetail extends BaseKJActivity implements IContractManageTestDetailView {
    @Bind(R.id.act_testdetail_list)
    public ListView act_testdetail_list;
    @Bind(R.id.empty_layout)
    public EmptyLayout mEmptyLayout;
    @Bind(R.id.title_tv)
    TextView titleTv;
    @Bind(R.id.testdetail_name)
    TextView testdetailName;
    @Bind(R.id.testdetail_classname)
    TextView testdetailClassname;
    @Bind(R.id.testdetail_time)
    TextView testdetailTime;

    private BaseAdapter adapter;
    String hosId,rpeportNo;

    IContractManageTestDetailPresenter presenter;

    List<ContractManageTestDetailBean.RowsBean> rowsBeans = new ArrayList<>();
    @Override
    public void setRootView() {
        setContentView(R.layout.act_testdetail);
        ButterKnife.bind(this);
    }

    //请求详情
    private void ApiForGetList() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("pageIndex", 1+"");
        params.put("pageSize", 99999+"");
        params.put("hospId", hosId);
        params.put("rpeportNo", rpeportNo.toUpperCase());
        presenter.showContractManageTestDetail(params);
    }

    @Override
    public void initData() {
        super.initData();
        presenter = new ContractManageTestDetailPresenter(this, new ContractManageModel());
        hosId = getIntent().getExtras().getString("hosId");
        rpeportNo = getIntent().getExtras().getString("rpeportNo");
        setContent();
        mEmptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
                ApiForGetList();
            }
        });

        ApiForGetList();
    }

    public void setTitle() {
        titleTv.setText("化验报告单");
    }

    @OnClick(R.id.back)
    public void onClick() {
        finish();
    }



    private void setContent()
    {
        testdetailName.setText("姓名："+getIntent().getExtras().getString("name"));
        testdetailClassname.setText("名称："+getIntent().getExtras().getString("reportname"));
        testdetailTime.setText(getIntent().getExtras().getString("reporttime"));
    }

    @Override
    public void showContractManageTestDetail(BaseEntity<ContractManageTestDetailBean> contractManageTestDetailBeanBaseEntity) {
        if(contractManageTestDetailBeanBaseEntity.getStatus().equals("200"))
        {
            rowsBeans = contractManageTestDetailBeanBaseEntity.getDatas().get(0).getRows();
            adapter = new ContractManageTestDetailAdapter(act_testdetail_list, rowsBeans, R.layout.testdetaillist_item);
            act_testdetail_list.setAdapter(adapter);
            mEmptyLayout.dismiss();
        }
        else {
            mEmptyLayout.setErrorType(EmptyLayout.NETWORK_ERROR);
            ViewInject.toast(contractManageTestDetailBeanBaseEntity.getMessage());
        }
    }
}
